using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using equalidator;
using NUnit.Framework;

namespace bowlingkata.tests
{
    [TestFixture]
    public class test_Frame_CreateFramesFromRolls
    {
        [Test]
        public void With_non_strike_frames()
        {
            var rolls = new[] {1, 2, 3, 7};
            var frames = Frame.CreateFramesFromRolls(rolls);
            Equalidator.AreEqual(new[]{new Frame(1,2,0), new Frame(3,7,0)},
                                 frames,
                                 true);
        }

        [Test]
        public void With_strike_frame()
        {
            var rolls = new[] { 10, 3, 4 };
            var frames = Frame.CreateFramesFromRolls(rolls);
            Assert.AreEqual(10, frames.ElementAt(0)[0]);
            Assert.AreEqual(0, frames.ElementAt(0)[1]);
            Assert.AreEqual(3, frames.ElementAt(1)[0]);
            Assert.AreEqual(4, frames.ElementAt(1)[1]);
        }

        [Test]
        public void With_one_additional_role_after_last_frame()
        {
            var rolls = new[] { 9, 1, 2 };
            var frames = Frame.CreateFramesFromRolls(rolls);
            Assert.AreEqual(9, frames.ElementAt(0)[0]);
            Assert.AreEqual(1, frames.ElementAt(0)[1]);
            Assert.AreEqual(2, frames.ElementAt(1)[0]);
            Assert.AreEqual(0, frames.ElementAt(1)[1]);
        }

        [Test]
        public void Spare_frame_with_strike_as_second_roll()
        {
            var rolls = new[] { 2, 3, 0, 10, 4, 5 };
            var frames = Frame.CreateFramesFromRolls(rolls);
            Equalidator.AreEqual(new[] { new Frame(2,3,0), 
                                         new Frame(0,10,0),
                                         new Frame(4,5,0) },
                                 frames,
                                 true);
        }
    }
}